package com.stp.config.filter;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * WebMvc配置
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Resource
    private SignInterceptor signInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //不拦截的地址
        List<String> excludedList = new ArrayList<>();
        //swagger地址
        excludedList.add("/swagger-ui.html");
        excludedList.add("/swagger-ui.html/**");
        excludedList.add("/webjars/**");
        excludedList.add("/swagger/**");
        excludedList.add("/doc.html");
        excludedList.add("/doc.html/**");
        excludedList.add("/swagger-resources/**");
        excludedList.add("/v2/**");
        excludedList.add("/favicon.ico");
        //生成应用id和密钥接口不拦截
        excludedList.add("/getSecret");


        registry.addInterceptor(signInterceptor)
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns(excludedList);//排除的请求
        super.addInterceptors(registry);
    }
}
